package main

import (
	"fmt"
	"time"
)

/**
	defer 实现的两阶段延迟执行，来优化 defer 实现的追踪执行时间
 */
func main() {
	defer TrackTime()()
	time.Sleep(800 * time.Millisecond)
}

func TrackTime() func() {
	now := time.Now()
	return func() {
		since := time.Since(now)
		fmt.Println("用时：", since)
	}
}